package main

import (
	"github.com/gorilla/websocket"
	"log"
	"net/http"
)

var upgrader = websocket.Upgrader{CheckOrigin: func(r *http.Request) bool {
	return true
}}

func main() {
	http.HandleFunc("/ws", func(writer http.ResponseWriter, request *http.Request) {
		var (
			conn *websocket.Conn
			err  error
			data []byte
		)
		if conn, err = upgrader.Upgrade(writer, request, nil); err != nil {
			return
		}
		defer conn.Close()

		for {
			if _, data, err = conn.ReadMessage(); err != nil {
				return
			}

			if err = conn.WriteMessage(websocket.TextMessage, data); err != nil {
				return
			}
		}

	})

	log.Println("http://0.0.0.0:7777/ws")
	http.ListenAndServe("0.0.0.0:7777", nil)
}
